package com.song.controller.setting;

import com.song.common.Result;
import com.song.controller.BaseController;
import com.song.entity.user.PwdEntity;
import com.song.entity.user.User;
import com.song.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("${api.version}/pwd")
public class PwdController extends BaseController {

    @Autowired
    private UserService userService;

    /**
     * 更新密码
     */
    @RequestMapping("/updatePwd")
    @ResponseBody
    public Result updatePwd(@Validated PwdEntity entity,Integer userId) {
        if (!entity.getConfirmPwd().equals(entity.getPassword())) {
            return error("两次填写密码不一致！");
        }
        User user = new User();
        user.setId(userId);
        user.setPassword(entity.getPassword());
        return userService.updateUser(user);
    }
}
